package com.xxl.baselib.baseui.fragment;

import android.app.ProgressDialog;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.xxl.baselib.baseui.activity.BaseWyActivity;
import com.xxl.baselib.util.StringUtils;


public abstract class BaseWyFragment extends Fragment {


    @Nullable
    @Override
    final public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        View contentView = inflater.inflate(getLayout(), container, false);
        initWyView(contentView);

        ViewGroup parent = (ViewGroup) contentView.getParent();
        if (parent != null) {
            parent.removeView(container);
        }
        needToDo();
        return contentView;
    }

    protected void needToDo() {

    }

    protected void hasBack(boolean hasBack) {
        getBaseActivity().setHasBack(hasBack);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initData();
    }

    protected abstract int getLayout();

    protected void initWyView(View view) {

    }

    protected void initData() {
    }

    final public BaseWyActivity getBaseActivity() {
        return (BaseWyActivity) getActivity();
    }

    public void setRightClick(View.OnClickListener onClickListener, String str) {
        getBaseActivity().setRightClick(onClickListener, str);
    }

    private static ProgressDialog progressDialog;

    public void showProgress(CharSequence message) {
        progressDialog = new ProgressDialog(getBaseActivity());
        progressDialog.setMessage(StringUtils.isEmpty(message) ? "请稍后..." : message);
        progressDialog.show();
    }

    public void hideProgress() {
        if (progressDialog != null && progressDialog.isShowing()) {
            progressDialog.dismiss();
        }
    }

    public void onEventListener() {
        onEventListener(null);
    }

    public void onEventListener(Object o) {

    }
}
